pull: new option --commit-metadata-only
authorGiuseppe Scrivano <gscrivan@redhat.com>
Fri, 24 Jul 2015 09:26:57 +0000 (11:26 +0200)
committerColin Walters <walters@verbum.org>
Fri, 24 Jul 2015 16:43:35 +0000 (12:43 -0400)
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Makefile-tests.am
doc/ostree-pull.xml
src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo.c
src/libostree/ostree-repo.h
src/ostree/ot-builtin-pull.c
tests/test-pull-commit-only.sh [new file with mode: 0755]

index cce78f39a2509b6fcbbae28a7990592a80931fc1..94dd79f57e897f0e340bfe6b1bc50a93b36b620c 100644 (file)
@@ -30,6 +30,7 @@ testfiles = test-basic \
        test-help \
        test-libarchive \
        test-pull-archive-z \
+       test-pull-commit-only \
        test-pull-corruption \
        test-pull-depth \
        test-pull-mirror-summary \
index 5247f44a6eb6b08c8a9ec8a89a0016907fc3d4a4..d915bcd27bb1a436e492da81b9d6cd4c2403062b 100644 (file)
@@ -57,6 +57,14 @@ Boston, MA 02111-1307, USA.
         <title>Options</title>
 
         <variablelist>
+            <varlistentry>
+                <term><option>--commit-metadata-only</option></term>
+
+                <listitem><para>
+                    Fetch only the commit metadata.
+                </para></listitem>
+            </varlistentry>
+
             <varlistentry>
                 <term><option>--disable-fsync</option></term>
 
index 71469e9fbc643058feb812104c7469545966edfa..aa8e6359d7dc39b3dff7d09947fe0e8bb3f7b058 100644 (file)
@@ -88,6 +88,7 @@ typedef struct {
   guint64           start_time;
 
   gboolean          is_mirror;
+  gboolean          is_commit_only;
 
   char         *dir;
   gboolean      commitpartial_exists;
@@ -1119,6 +1120,11 @@ scan_one_metadata_object_c (OtPullData         *pull_data,
       do_fetch_detached = (objtype == OSTREE_OBJECT_TYPE_COMMIT);
       enqueue_one_object_request (pull_data, tmp_checksum, objtype, do_fetch_detached, FALSE);
     }
+  else if (objtype == OSTREE_OBJECT_TYPE_COMMIT && pull_data->is_commit_only)
+    {
+      ret = TRUE;
+      goto out;
+    }
   else if (is_stored)
     {
       gboolean do_scan = pull_data->transaction_resuming || is_requested || pull_data->commitpartial_exists;
@@ -1654,6 +1660,7 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
     g_return_val_if_fail (dir_to_pull[0] == '/', FALSE);
 
   pull_data->is_mirror = (flags & OSTREE_REPO_PULL_FLAGS_MIRROR) > 0;
+  pull_data->is_commit_only = (flags & OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY) > 0;
 
   pull_data->async_error = error;
   pull_data->main_context = g_main_context_ref_thread_default ();
@@ -2160,7 +2167,7 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
     }
 
   /* iterate over commits fetched and delete any commitpartial files */
-  if (!dir_to_pull)
+  if (!dir_to_pull && !pull_data->is_commit_only)
     {
       g_hash_table_iter_init (&hash_iter, requested_refs_to_fetch);
       while (g_hash_table_iter_next (&hash_iter, &key, &value))
index 31c3b68c65b34c7c9e596752a39f53434b45433f..28d67b2cb06e0f56d95ffcc9ad0a43f6f10a7336 100644 (file)
@@ -3674,6 +3674,9 @@ ostree_repo_read_commit (OstreeRepo   *self,
  * the @refs_to_fetch is %NULL, and the remote repository contains a
  * summary file, then all refs will be fetched.
  *
+ * If @flags contains %OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY, then only the
+ * metadata for the commits in @refs_to_fetch is pulled.
+ *
  * Warning: This API will iterate the thread default main context,
  * which is a bug, but kept for compatibility reasons.  If you want to
  * avoid this, use g_main_context_push_thread_default() to push a new
index 992cf1e148d6ec52733a51c0fde5d73540fb5439..38a261f90ddf4ab707f90e32103732a2348a107f 100644 (file)
@@ -693,10 +693,12 @@ gboolean ostree_repo_prune (OstreeRepo        *self,
  * OstreeRepoPullFlags:
  * @OSTREE_REPO_PULL_FLAGS_NONE: No special options for pull
  * @OSTREE_REPO_PULL_FLAGS_MIRROR: Write out refs suitable for mirrors
+ * @OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY: Fetch only the commit metadata
  */
 typedef enum {
   OSTREE_REPO_PULL_FLAGS_NONE,
-  OSTREE_REPO_PULL_FLAGS_MIRROR
+  OSTREE_REPO_PULL_FLAGS_MIRROR = (1 << 0),
+  OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY = (1 << 1)
 } OstreeRepoPullFlags;
 
 gboolean ostree_repo_pull (OstreeRepo             *self,
index 9192e7cc5bd040d75d54aa5e24e62d165d478042..6aae82056a5142efae4dec77848b08718bb2bec5 100644 (file)
 
 static gboolean opt_disable_fsync;
 static gboolean opt_mirror;
+static gboolean opt_commit_only;
 static gboolean opt_disable_static_deltas;
 static char* opt_subpath;
 static int opt_depth = 0;
  
  static GOptionEntry options[] = {
+   { "commit-metadata-only", 0, 0, G_OPTION_ARG_NONE, &opt_commit_only, "Fetch only the commit metadata", NULL },
    { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL },
    { "disable-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_disable_static_deltas, "Do not use static deltas", NULL },
    { "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, "Write refs suitable for a mirror", NULL },
@@ -91,6 +93,9 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
   if (opt_mirror)
     pullflags |= OSTREE_REPO_PULL_FLAGS_MIRROR;
 
+  if (opt_commit_only)
+    pullflags |= OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY;
+
   if (strchr (argv[1], ':') == NULL)
     {
       remote = g_strdup (argv[1]);
diff --git a/tests/test-pull-commit-only.sh b/tests/test-pull-commit-only.sh
new file mode 100755 (executable)
index 0000000..1cdc675
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+set -e
+
+. $(dirname $0)/libtest.sh
+
+setup_fake_remote_repo1 "archive-z2"
+
+echo '1..1'
+
+cd ${test_tmpdir}
+mkdir repo
+${CMD_PREFIX} ostree --repo=repo init
+${CMD_PREFIX} ostree --repo=repo remote add --set=gpg-verify=false origin $(cat httpd-address)/ostree/gnomerepo
+
+ostree --repo=repo pull --commit-metadata-only origin main
+find repo/objects -name '*.commit' | wc -l > commitcount
+assert_file_has_content commitcount "^1$"
+ostree --repo=repo fsck
+
+find repo/objects -name '*.file.*' | wc -l > commitcount
+assert_file_has_content commitcount "^0$"
+
+find repo/objects -name '*.dirtree' | wc -l > commitcount
+assert_file_has_content commitcount "^0$"
+
+echo "ok pull commit metadata only"